(function ($) {
	var sourceData;
	var perInfo,pageType,nurseid,perid
	var domArr = [{'domId':'specialNurType','tip':'请选择专科护士','type':'list','key':'specialNurType'},
			{'domId':'specialType','tip':'请选择专科证书','type':'list','key':'specialType'},
			{'domId':'specialAuth','tip':'请选择专科认证单位','type':'list','key':'specialAuth'},
			{'domId':'specialAuthDate','tip':'选择认证日期','type':'date','key':'specialAuthDate'}]
	var unUploadFiles=[] //未上传的图片
	$.init();
	$.plusReady(function() {
		baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	//1^26||1^66||1^67||1^2022-08-15^Y^
	function submitNewData(){
		blurAllInput()
		var parr = perid+'^'
		for (var i = 0; i < domArr.length; i++) {
			var oneDom = domArr[i]
			var dom = $('#'+oneDom['domId'])[0]
			var domValue = dom.innerText
			if (oneDom['type'] == 'list') {
				domValue = dom.getAttribute('data-id')
				if (domValue == undefined) {
					domValue=""
				}
			}
			if (domValue == '' && oneDom['tip']!= '') {
				mui.toast(oneDom['tip'])
				return
			}
			parr += domValue+'^'
		}
		
		var status = this.getAttribute('data-id');
		parr +=status+'^'
		// console.log(parr)
		var pdict = {'parr':parr,'nurseid':nurseid}
		var paramDict = {'method':'web.INMSpecialComm:SaveSpecial','params':JSON.stringify(pdict),'type':'Method'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var msgcode =result['msgcode']
			if (msgcode == '-1') {
				mui.toast(result['msg'])
				return 
			}
			if (unUploadFiles.length==0 ) {
				plus.webview.getWebviewById('../WKPlatformPages/apply/applyList.html').evalJS('detailChanged()')
				mui.back()
				return;
			}
			var path = 'special'
			var method = 'web.INMPersonComm:InsertPic'
			var paramDict={'id':perid,'path':path,'method':method,'otherParams':result['msg']+'||2||','imgArr':unUploadFiles,'spStr':'」'}
			saveFileAction(paramDict,function(flag){
				if (!flag) {
					return
				}
				unUploadFiles=[]
				plus.webview.getWebviewById('../WKPlatformPages/apply/applyList.html').evalJS('detailChanged()')
				mui.back()
			})
			
		}, function(errorStr) {
			mui.toast(errorStr)
		});
	}
	
	
	//选择日期
	function selectDateNew(){
		blurAllInput()
		var _self = this
		if(_self.picker) {
			_self.picker.show(function(rs) {
				_self.innerText = rs.text
				_self.classList.remove('noTextTip')
				_self.picker.dispose();
				_self.picker = null;
			});
		} else {
			var options = {"type":"date","endDate": new Date()};
			_self.picker = new mui.DtPicker(options);
			_self.picker.show(function(rs) {
				_self.innerText = rs.text
				_self.classList.remove('noTextTip')
				_self.picker.dispose();
				_self.picker = null;
			});
		}
	}

	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		mui.previewImage();
		var self = plus.webview.currentWebview()
		pageType = self.pageType
		perInfo = self.perInfo
		nurseid = perInfo['loginID']
		perid = perInfo['loginPerID']
		$('#CreatorName')[0].innerText = perInfo['loginName']
		$('#applyLoc')[0].innerText = perInfo['loginWardDesc']
		//关闭按钮
		mui('body').on('tap','#closeBtn',function(){
			blurAllInput()
			mui.back()
		})
		//保存提交按钮
		mui('body').on('tap','.submitBtn',submitNewData)
		// 日期
		mui('#UL').on('tap','.dateType',selectDateNew);
		//列表
		mui('#UL').on('tap','.listType',downListElementTapped);
		window.addEventListener('resize',windowResize)
		$('#addFileBtn').on('change','input',function(){
			var imgArr = this.files
			var name = imgArr[0]['name']
			if (fileTypeIcon(name) != 'img') {
				mui.toast('仅支持图片哦~~')
				return;
			}
			unUploadFiles = afterSelectImageFile('fileUL',unUploadFiles,imgArr)
		});
		//监听文件删除按钮
		mui('#fileUL').on('tap','.mui-icon-closeempty',function(){
			var method = getDeleteFileMethod(pageType)
			var paramDict={'imgArr':unUploadFiles,'method':method,'nurseid':nurseid}
			deleteFileBtnTapped(this,paramDict,function(flag,arr){
				if (arr) {
					unUploadFiles = arr
				}
			});
		}) 
		mui.back = function(){
			if (unUploadFiles.length > 0) {
				mui.confirm('您有未上传的文件','温馨提示',['放弃','继续操作'],function (e) {
					if (e.index == 0) {
						plus.nativeUI.closeWaiting()
						plus.webview.currentWebview().close()
					}
				},'div')
				return
			}
			plus.nativeUI.closeWaiting()
			plus.webview.currentWebview().close()
		}
	}
	
})(mui)

